Turn the pixbuf attributes into (construct-only, but always readable)
authorMatthias Clasen <maclas@gmx.de>
Sat, 3 Jan 2004 23:45:06 +0000 (23:45 +0000)
committerMatthias Clasen <matthiasc@src.gnome.org>
Sat, 3 Jan 2004 23:45:06 +0000 (23:45 +0000)
Sun Jan  4 00:44:57 2004  Matthias Clasen  <maclas@gmx.de>

* gdk-pixbuf.c (gdk_pixbuf_class_init): Turn the pixbuf
attributes into (construct-only, but always readable)
properties.  (#130196)

* gdk-pixbuf-data.c (gdk_pixbuf_new_from_data): Set properties
in g_object_new().

gdk-pixbuf/ChangeLog
gdk-pixbuf/gdk-pixbuf-data.c
gdk-pixbuf/gdk-pixbuf.c

index b24edaabe006c3c5b96d0fda42549aefc4b0619a..f11a942d3c27746b544b2f268c544e8e5ee72099 100644 (file)
@@ -1,3 +1,12 @@
+Sun Jan  4 00:44:57 2004  Matthias Clasen  <maclas@gmx.de>
+
+       * gdk-pixbuf.c (gdk_pixbuf_class_init): Turn the pixbuf 
+       attributes into (construct-only, but always readable) 
+       properties.  (#130196)
+
+       * gdk-pixbuf-data.c (gdk_pixbuf_new_from_data): Set properties
+       in g_object_new().
+
 Mon Dec 22 01:35:36 2003  Matthias Clasen  <maclas@gmx.de>
 
        * Makefile.am (gdk-pixbuf.loaders): Fix building with
index 0686bdefc79c5f8c47c40d30d4838135dba6abbb..1121338358438aec8ab79e8c8ee3f1b3a6de496d 100644 (file)
@@ -61,16 +61,17 @@ gdk_pixbuf_new_from_data (const guchar *data, GdkColorspace colorspace, gboolean
        g_return_val_if_fail (width > 0, NULL);
        g_return_val_if_fail (height > 0, NULL);
 
-       pixbuf = g_object_new (GDK_TYPE_PIXBUF, NULL);
+       pixbuf = g_object_new (GDK_TYPE_PIXBUF, 
+                              "colorspace", colorspace,
+                              "n_channels", has_alpha ? 4 : 3,
+                              "bits_per_sample", bits_per_sample,
+                              "has_alpha", has_alpha ? TRUE : FALSE,
+                              "width", width,
+                              "height", height,
+                              "rowstride", rowstride,
+                              "pixels", data,
+                              NULL);
         
-       pixbuf->colorspace = colorspace;
-       pixbuf->n_channels = has_alpha ? 4 : 3;
-       pixbuf->bits_per_sample = bits_per_sample;
-       pixbuf->has_alpha = has_alpha ? TRUE : FALSE;
-       pixbuf->width = width;
-       pixbuf->height = height;
-       pixbuf->rowstride = rowstride;
-       pixbuf->pixels = (guchar *) data;
        pixbuf->destroy_fn = destroy_fn;
        pixbuf->destroy_fn_data = destroy_fn_data;
 
index 1a64de72dadb3dfb6efc18c24ca72e7147e52dbb..986b40fc4e6ca582c96d4f2283b4224e427a7d4d 100644 (file)
 #include "gdk-pixbuf.h"
 #include "gdk-pixbuf-private.h"
 
-static void gdk_pixbuf_class_init  (GdkPixbufClass *klass);
-static void gdk_pixbuf_finalize    (GObject        *object);
+static void gdk_pixbuf_class_init   (GdkPixbufClass *klass);
+static void gdk_pixbuf_finalize     (GObject        *object);
+static void gdk_pixbuf_set_property (GObject        *object,
+                                    guint           prop_id,
+                                    const GValue   *value,
+                                    GParamSpec     *pspec);
+static void gdk_pixbuf_get_property (GObject        *object,
+                                    guint           prop_id,
+                                    GValue         *value,
+                                    GParamSpec     *pspec);
 
 \f
+enum 
+{
+  PROP_0,
+  PROP_COLORSPACE,
+  PROP_N_CHANNELS,
+  PROP_HAS_ALPHA,
+  PROP_BITS_PER_SAMPLE,
+  PROP_WIDTH,
+  PROP_HEIGHT,
+  PROP_ROWSTRIDE,
+  PROP_PIXELS
+};
 
 static gpointer parent_class;
 
@@ -71,6 +91,91 @@ gdk_pixbuf_class_init (GdkPixbufClass *klass)
         parent_class = g_type_class_peek_parent (klass);
         
         object_class->finalize = gdk_pixbuf_finalize;
+        object_class->set_property = gdk_pixbuf_set_property;
+        object_class->get_property = gdk_pixbuf_get_property;
+        
+        g_object_class_install_property (object_class,
+                                         PROP_N_CHANNELS,
+                                         g_param_spec_int ("n_channels",
+                                                           _("Number of Channels"),
+                                                           _("The number of samples per pixel"),
+                                                           0,
+                                                           G_MAXINT,
+                                                           3,
+                                                           G_PARAM_READWRITE |
+                                                           G_PARAM_CONSTRUCT_ONLY));
+
+        g_object_class_install_property (object_class,
+                                         PROP_COLORSPACE,
+                                         g_param_spec_enum ("colorspace",
+                                                            _("Colorspace"),
+                                                            _("The colorspace in which the samples are interpreted"),
+                                                            GDK_TYPE_COLORSPACE,
+                                                            GDK_COLORSPACE_RGB,
+                                                            
+                                                            G_PARAM_READWRITE |
+                                                            G_PARAM_CONSTRUCT_ONLY));
+
+        g_object_class_install_property (object_class,
+                                         PROP_HAS_ALPHA,
+                                         g_param_spec_boolean ("has_alpha",
+                                                               _("Has Alpha"),
+                                                               _("Whether the pixbuf has an alpha channel"),
+                                                               FALSE,
+                                                               G_PARAM_READWRITE |
+                                                               G_PARAM_CONSTRUCT_ONLY));
+
+        g_object_class_install_property (object_class,
+                                         PROP_BITS_PER_SAMPLE,
+                                         g_param_spec_int ("bits_per_sample",
+                                                           _("Bits per Sample"),
+                                                           _("The number of bits per sample"),
+                                                           1,
+                                                           16,
+                                                           8,
+                                                           G_PARAM_READWRITE |
+                                                           G_PARAM_CONSTRUCT_ONLY));
+
+        g_object_class_install_property (object_class,
+                                         PROP_WIDTH,
+                                         g_param_spec_int ("width",
+                                                           _("Width"),
+                                                           _("The number of columns of the pixbuf"),
+                                                           1,
+                                                           G_MAXINT,
+                                                           1,
+                                                           G_PARAM_READWRITE |
+                                                           G_PARAM_CONSTRUCT_ONLY));
+
+        g_object_class_install_property (object_class,
+                                         PROP_HEIGHT,
+                                         g_param_spec_int ("height",
+                                                           _("Height"),
+                                                           _("The number of rows of the pixbuf"),
+                                                           1,
+                                                           G_MAXINT,
+                                                           1,
+                                                           G_PARAM_READWRITE |
+                                                           G_PARAM_CONSTRUCT_ONLY));
+
+        g_object_class_install_property (object_class,
+                                         PROP_ROWSTRIDE,
+                                         g_param_spec_int ("rowstride",
+                                                           _("Rowstride"),
+                                                           _("The number of bytes between the start of a row and the start of the next row"),
+                                                           1,
+                                                           G_MAXINT,
+                                                           1,
+                                                           G_PARAM_READWRITE |
+                                                           G_PARAM_CONSTRUCT_ONLY));
+
+        g_object_class_install_property (object_class,
+                                         PROP_PIXELS,
+                                         g_param_spec_pointer ("pixels",
+                                                               _("Pixels"),
+                                                               _("A pointer to the pixel data of the pixbuf"),
+                                                               G_PARAM_READWRITE |
+                                                               G_PARAM_CONSTRUCT_ONLY));
 }
 
 static void
@@ -580,6 +685,86 @@ gdk_pixbuf_set_option (GdkPixbuf   *pixbuf,
         return TRUE;
 }
 
+static void
+gdk_pixbuf_set_property (GObject         *object,
+                        guint            prop_id,
+                        const GValue    *value,
+                        GParamSpec      *pspec)
+{
+  GdkPixbuf *pixbuf = GDK_PIXBUF (object);
+
+  switch (prop_id)
+          {
+          case PROP_COLORSPACE:
+                  pixbuf->colorspace = g_value_get_enum (value);
+                  break;
+          case PROP_N_CHANNELS:
+                  pixbuf->n_channels = g_value_get_int (value);
+                  break;
+          case PROP_HAS_ALPHA:
+                  pixbuf->has_alpha = g_value_get_boolean (value);
+                  break;
+          case PROP_BITS_PER_SAMPLE:
+                  pixbuf->bits_per_sample = g_value_get_int (value);
+                  break;
+          case PROP_WIDTH:
+                  pixbuf->width = g_value_get_int (value);
+                  break;
+          case PROP_HEIGHT:
+                  pixbuf->height = g_value_get_int (value);
+                  break;
+          case PROP_ROWSTRIDE:
+                  pixbuf->rowstride = g_value_get_int (value);
+                  break;
+          case PROP_PIXELS:
+                  pixbuf->pixels = (guchar *) g_value_get_pointer (value);
+                  break;
+          default:
+                  G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+                  break;
+          }
+}
+
+static void
+gdk_pixbuf_get_property (GObject         *object,
+                        guint            prop_id,
+                        GValue          *value,
+                        GParamSpec      *pspec)
+{
+  GdkPixbuf *pixbuf = GDK_PIXBUF (object);
+  
+  switch (prop_id)
+          {
+          case PROP_COLORSPACE:
+                  g_value_set_enum (value, gdk_pixbuf_get_colorspace (pixbuf));
+                  break;
+          case PROP_N_CHANNELS:
+                  g_value_set_int (value, gdk_pixbuf_get_n_channels (pixbuf));
+                  break;
+          case PROP_HAS_ALPHA:
+                  g_value_set_boolean (value, gdk_pixbuf_get_has_alpha (pixbuf));
+                  break;
+          case PROP_BITS_PER_SAMPLE:
+                  g_value_set_int (value, gdk_pixbuf_get_bits_per_sample (pixbuf));
+                  break;
+          case PROP_WIDTH:
+                  g_value_set_int (value, gdk_pixbuf_get_width (pixbuf));
+                  break;
+          case PROP_HEIGHT:
+                  g_value_set_int (value, gdk_pixbuf_get_height (pixbuf));
+                  break;
+          case PROP_ROWSTRIDE:
+                  g_value_set_int (value, gdk_pixbuf_get_rowstride (pixbuf));
+                  break;
+          case PROP_PIXELS:
+                  g_value_set_pointer (value, gdk_pixbuf_get_pixels (pixbuf));
+                  break;
+          default:
+                  G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+                  break;
+          }
+}
+
 \f
 
 /* Include the marshallers */